<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <body>

        <ui:composition template="./../../WEB-INF/templates/noFooterTemplate.xhtml">
            <ui:define name="content">

                <h:form id="viewAdminCompanyForm">
                    <p:growl id="growl"/>
                    <p:toolbar id="tb">  
                        <p:toolbarGroup align="left"> 
                            <p:commandButton id="removeFilterButton" value="#{messages.CleanFilters}" onclick="companiesTable.clearFilters()"/> 
                            <p:commandButton id="viewProfileButton" disabled="#{adminCompanyBean.chosenEntity==null}" value="#{messages.EditProfile}/ #{messages.ViewProfile}" action="#{adminEditCompanyBean.fillEditCompanyBean(adminCompanyBean.chosenEntity)}"/>  
                            <p:commandButton id="removeCompanyButton" disabled="#{adminCompanyBean.chosenEntity==null}" value="#{messages.RemoveCompany}" onclick="removeCompanyDialog.show();"> 
                            </p:commandButton>
                        </p:toolbarGroup>  
                    </p:toolbar> 
                    <p:panel id="companyDatatable" styleClass="noBorder noMargin noPadding">
                        <p:dataTable var="company" value="#{adminCompanyBean.entityList}" rowKey="#{company.idCompany}" selection="#{adminCompanyBean.chosenEntity}" selectionMode="single" filteredValue="#{adminCompanyBean.filteredEntitiesList}"
                                     paginator="true" rows="25" widgetVar="companiesTable" 
                                     paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                     rowsPerPageTemplate="25,50,100">  
                            <p:ajax event="rowSelect" update=":viewAdminCompanyForm:tb "/>
                            <p:ajax event="rowUnselect" update=":viewAdminCompanyForm:tb"/>
                            <p:column filterBy="#{company.name}" filterMatchMode="contains" sortBy="#{company.name}" headerText="#{messages.Name}">  
                                <h:outputText value="#{company.name}" />  
                            </p:column>  
                            <p:column filterBy="#{company.idUser.email}" filterMatchMode="contains" sortBy="#{company.idUser.email}" headerText="#{messages.Email}">  
                                <h:outputText value="#{company.idUser.email}" />  
                            </p:column>  
                            <p:column filterBy="#{company.phone}" filterMatchMode="contains" sortBy="#{company.phone}" headerText="#{messages.Phone}">  
                                <h:outputText value="#{company.phone}" />  
                            </p:column>  
                            <p:column sortBy="#{company.availableCredits}" headerText="#{messages.Credits}">  
                                <h:outputText value="#{company.availableCredits}" />  
                            </p:column>  
                            <p:column  headerText="#{messages.RelatedUsers}">  
                                <h:outputText value="#{adminCompanyBean.getNumRelatedUserFromUser(company)}" />  
                            </p:column>
                            <p:column sortBy="#{company.idUser.creationDate}" headerText="#{messages.RegisterDate}">  
                                <h:outputText value="#{company.idUser.creationDate}">
                                    <f:convertDateTime pattern="d/M/yyyy - HH:mm"></f:convertDateTime>
                                </h:outputText>
                            </p:column> 
                            <p:column sortBy="#{company.idUser.lastDate}" headerText="#{messages.LastDate}">  
                                <h:outputText value="#{company.idUser.lastDate}">
                                    <f:convertDateTime pattern="d/M/yyyy - HH:mm"></f:convertDateTime>
                                </h:outputText>
                            </p:column> 
                            <p:column sortBy="#{company.idUser.logins}" headerText="#{messages.Logins}">  
                                <h:outputText value="#{company.idUser.logins}" />  
                            </p:column>
                            <p:column filterOptions="#{adminCompanyBean.trueFalseOptions}" 
                                      filterMatchMode="exact" filterBy="#{company.idUser.active}" sortBy="#{company.idUser.active}" headerText="#{messages.Active}">  
                                <h:outputText value="#{messages.Yes}" rendered="#{company.idUser.active}" />  
                                <h:outputText value="#{messages.No}" rendered="#{!company.idUser.active}" />  
                            </p:column>  
                        </p:dataTable> 
                    </p:panel>
                    <p:dialog modal="true" style="width:250px;" header="#{messages.AreYouSure}" resizable="false" id="removeCompanyDialog" widgetVar="removeCompanyDialog"  draggable="true" closable="true">  
                        <p:commandButton process="@this" value="#{messages.No}" onsuccess="removeCompanyDialog.hide();" update="removeCompanyDialog"/>  
                        <p:commandButton process="@parent" value="#{messages.Yes}" actionListener="#{adminCompanyBean.removeCompany()}" onsuccess="removeCompanyDialog.hide();" update=":viewAdminCompanyForm:companyDatatable removeCompanyDialog"/> 
                    </p:dialog> 
                </h:form>

            </ui:define>
        </ui:composition>

    </body>
</html>
